<!-- 入会须知 -->
<template>
  <a-form-model ref="ruleForm" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
    <a-form-model-item label="申请须知">
      <div class="_mb-10">
        <a-switch v-model="form.isApplyExplain" />
        <span class="_ml-10">开启后用户申请入会时须先阅读【申请须知】，再填写表单</span>
      </div>
      <Ueditor v-model="form.applyExplain" editorId="joinConfig" />
    </a-form-model-item>
    <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
      <div style="text-align: center">
        <a-button
          type="primary"
          size="large"
          :loading="submitLoading"
          style="margin-left: 10px; width: 400px"
          @click="onSubmit"
        >
          保存
        </a-button>
      </div>
    </a-form-model-item>
  </a-form-model>
</template>

<script>
import Ueditor from '@/components/Ueditor'
import { getByIdApplyExplain, updateApplyExplain } from '@/api/member/member'
export default {
  props: ['type'],
  components: {
    Ueditor
  },
  data() {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      form: {
        applyExplain: undefined,
        applyAttachment: undefined,
        isApplyExplain: false,
      },
      submitLoading: false,
    }
  },
  computed: {},
  watch: {},
  methods: {
    uploadSuccess(fileUrl) {
      this.form.applyAttachment = fileUrl
      console.log('this.form---->', this.form)
    },
    async get_byIdApplyExplain() {
      let res = await getByIdApplyExplain(this.type)
      this.form.applyExplain = res.data.applyExplain
      this.form.applyAttachment = res.data.applyAttachment
      this.form.isApplyExplain = res.data.isApplyExplain === 1
    },
    async onSubmit() {
      try {
        this.submitLoading = true
        let { code, msg } = await updateApplyExplain({
          customFormId: this.type,
          ...this.form,
          isApplyExplain: this.form.isApplyExplain ? 1 : 0,
        })
        this.submitLoading = false
        this.$message[code === 0 ? 'success' : 'error'](msg)
        this.get_byIdApplyExplain()
      } catch (error) {
        this.submitLoading = false
      }
    },
  },
  created() {
    this.get_byIdApplyExplain()
  },
  mounted() {},
}
</script>
<style scoped>
</style>